package com.ateam.dao.impl;

import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;

import com.ateam.dao.UsersDao;
import com.ateam.pojo.Users;

/** 
* @author WuYuan
* 
*/
public class UsersDaoImpl implements UsersDao {
	private SqlSessionTemplate sqlSessionTemplate;
	
	public SqlSessionTemplate getSqlSessionTemplate() {
		return sqlSessionTemplate;
	}

	public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
		this.sqlSessionTemplate = sqlSessionTemplate;
	}
	@Override
	public int addUser(Users u) throws Exception {
		return sqlSessionTemplate.insert("addUser",u);
	}

	@Override
	public Users getUserByEmail(String email) throws Exception {
		return  (Users)sqlSessionTemplate.selectOne("getUserByEmail", email);
	}
	

	@Override
	public Users getUserByUserid(int userid) throws Exception {
		return  (Users)sqlSessionTemplate.selectOne("getUserByUserid", userid);
	}

	@Override
	public Users getUserLogin(Users u) throws Exception {
		return  (Users)sqlSessionTemplate.selectOne("getUserLogin", u);
	}

	@Override
	public int updateUser(Users u) throws Exception {
		return sqlSessionTemplate.update("updateUser",u);
	}

	@Override
	public List<Users> getUsersByCompanyid(int companyid) throws Exception {
		return sqlSessionTemplate.selectList("getUsersByCompanyid", companyid);
	}

	@Override
	public List<Users> getUsersByProjectid(int projectid) throws Exception {
		return sqlSessionTemplate.selectList("getUsersByProjectid", projectid);
	}

	@Override
	public List<Users> getUsersByNoProjectid(int companyid, int projectid) throws Exception {
		Object [] objects =new Object[]{companyid,projectid};
		return sqlSessionTemplate.selectList("getUsersByNoProjectid", objects);
	}

	@Override
	public int addUserProject(int userid, int projectid) throws Exception {
		Object [] objects =new Object[]{userid,projectid};
		return sqlSessionTemplate.insert("addUserProject", objects);
	}

	@Override
	public List<Users> getUsersByGroupid(int groupid) throws Exception {
		return sqlSessionTemplate.selectList("getUsersByGroupid", groupid);
	}

	@Override
	public List<Users> getUsersByNoGroupid(int companyid, int groupid) throws Exception {
		Object [] objects =new Object[]{companyid,groupid};
		return sqlSessionTemplate.selectList("getUsersByNoGroupid", objects);
	}

	@Override
	public int addUserGroup(int userid, int groupid) throws Exception {
		Object [] objects =new Object[]{userid,groupid};
		return sqlSessionTemplate.insert("addUserGroup", objects);
	}

	@Override
	public List<Users> getCompanyApplyer(int companyid) throws Exception {
		return sqlSessionTemplate.selectList("getCompanyApplyer", companyid);
	}


}
